#!/usr/bin/perl

use strict;
use Data::Dumper;

sub check_map($)
{
    my $map_file = shift;

    open DEVTABLE, $map_file || die "Cannot open file $map_file\n";

    my %msa = (TSE => {}, ASE => {});
    while (<DEVTABLE>) {
        chomp;
        my @fields = split /\s+/;
        my $name = $fields[0];
        my $wwn_p = $fields[3];
        my $lun_p = $fields[5];
        my $wwn_b = $fields[6];
        my $lun_b = $fields[8];

        $msa{$wwn_p}[$lun_p] = "database/$name";
        $msa{$wwn_b}[$lun_b] = "databasem/$name";

        $msa{TSE}->{$wwn_p} = 0 if (! defined $msa{TSE}->{$wwn_p});
        $msa{ASE}->{$wwn_p} = 0 if (! defined $msa{ASE}->{$wwn_p});

        $msa{TSE}->{$wwn_p}++ if ($name =~ /DB/);
        $msa{ASE}->{$wwn_p}++ if ($name =~ /AU/);
    }
    close(DEVTABLE);

    print Dumper(\%msa);
}

#for my $devtable (@ARGV) {
    check_map("table_map");
#}
